"""
sequential
"""
import torch
import torchvision
from torch import nn
from torch.nn import Sequential
from torch.utils.data import DataLoader
from torch.utils.tensorboard import SummaryWriter


# 原始输入3*32*32
class Tudui(nn.Module):
    def __init__(self):
        super(Tudui, self).__init__()
        """
        # 第一层卷积输出32*32*32
        self.conv1 = nn.Conv2d(in_channels=3, out_channels=32, kernel_size=5, padding=2)
        # 池化输出32*16*16
        self.maxpool1 = nn.MaxPool2d(2)
        # 第二层卷积输出32*16*16
        self.conv2 = nn.Conv2d(32, 32, 5, padding=2)
        # 池化输出32*8*8
        self.maxpool2 = nn.MaxPool2d(2)
        # 第三层卷积输出64*8*8
        self.conv3 = nn.Conv2d(32, 64, 5, padding=2)
        # 池化输出64*4*4
        self.maxpool3 = nn.MaxPool2d(2)
        # 数据展平输出64*4*4=1024
        self.flatten = nn.Flatten()
        # 线性层输入1024，输出64
        self.linear1 = nn.Linear(1024, 64)
        # 线性层输入64，输出10
        self.linear2 = nn.Linear(64, 10)
        """

        self.model1 = Sequential(
            nn.Conv2d(3, 32, 5, padding=2),
            nn.MaxPool2d(2),
            nn.Conv2d(32, 32, 5, padding=2),
            nn.MaxPool2d(2),
            nn.Conv2d(32, 64, 5, padding=2),
            nn.MaxPool2d(2),
            nn.Flatten(),
            nn.Linear(1024, 64),
            nn.Linear(64, 10)
        )

    def forward(self, x):
        """
        x = self.conv1(x)
        x = self.maxpool1(x)
        x = self.conv2(x)
        x = self.maxpool2(x)
        x = self.conv3(x)
        x = self.maxpool3(x)
        x = self.flatten(x)
        x = self.linear1(x)
        x = self.linear2(x)
        """
        x = self.model1(x)

        return x


tudui = Tudui()
print(tudui)

# 测试网络正确性
input = torch.ones((64, 3, 32, 32))
output = tudui(input)
print(output.shape)

writer = SummaryWriter("../logs_seq")
writer.add_graph(tudui,input)
writer.close()
